﻿using MediatR;
using SlaughterItem.Common.Domains.Warehouse;
using SlaughterItem.Common.Dtos;
using SlaughterItem.Common.Infrastructures.Interfaces;
using SlaughterItem.Common.Infrastructures.Repositories;
using SlaughterItem.Enum;

namespace GetSlaughterItem.API.Application.Commands.Week02.Scale
{
    public class WarehouseDataShowHandler : IRequestHandler<WarehouseDataShowCommand, Result>
    {
        IBaseRepositoryGet<WarehouseData> WarehouseDataRep;
        IBaseRepositoryGet<DepotType> DepotTypeRep;

        public WarehouseDataShowHandler(IBaseRepositoryGet<WarehouseData> warehouseDataRep, IBaseRepositoryGet<DepotType> depotTypeRep)
        {
            WarehouseDataRep = warehouseDataRep;
            DepotTypeRep = depotTypeRep;
        }

        /// <summary>
        /// 查询仓库  绑定下拉框
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task<Result> Handle(WarehouseDataShowCommand request, CancellationToken cancellationToken)
        {
            var result = new Result() { Code = (int)CommonErrorCode.Search };
            try
            {
                var list = from a in  DepotTypeRep.GetAll()
                           select new
                           {
                               a.DepotTypeId,
                               a.DepotTypeName
                           };
                if (list != null)
                {
                    result.Code = (int)CommonErrorCode.Success;
                    result.Data = list;
                    result.Msg = "成功";
                }
            }
            catch (Exception)
            {

                throw;
            }
            return result;
        }
    }
}
